<?php

use Illuminate\Database\Seeder;
use App\Models\Action;

class ActionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 清理菜单数据
        $connection = new \MongoDB\Client('mongodb://'.env('DB_HOST'));

        $collection = $connection->selectCollection(env('DB_DATABASE'), 'actions');
        $collection->drop();

        $file = database_path('seeds/actions.yml');
        $raw = yaml_parse_file($file);
        Action::unguard();
        foreach($raw as $i => $item) {
            $action = Action::firstOrCreate([
               'key' => $item['key']
            ]);
            $action->update($item);
        }
    }
}
